package com.sscl.baselibrary.exts

import android.graphics.Bitmap
import android.util.Base64
import java.io.ByteArrayOutputStream

/**
 * 压缩bitmap 并 转为 base64
 *
 * @param quality 质量,100表示不压缩
 * @return base64
 */
fun Bitmap.toBase64String(quality: Int = 100): String {
    val bos = ByteArrayOutputStream()
    this.compress(Bitmap.CompressFormat.JPEG, quality, bos)
    val bytes = bos.toByteArray()
    return Base64.encodeToString(bytes, Base64.DEFAULT)
}